package com.tjf.lib_core;

import android.app.Application;
import android.os.Build;
import android.os.Environment;

import com.alibaba.android.arouter.launcher.ARouter;
import com.tencent.bugly.crashreport.CrashReport;
import com.tjf.lib_core.exceptions.AppCrashHandler;
import com.tjf.lib_network.HttpHelper;
import com.tjf.lib_network.okhttp.OkhttpUtil;
import com.tjf.lib_utils.LogsUtils;
import com.tjf.lib_utils.ShareUtils;

import java.io.File;

import tech.gujin.toast.ToastUtil;

/**
 * @author: tjf
 * @date: 2024-01-16
 * @desc： 基础baseApp
 */
public class BaseApp extends Application {
    public static Application application;

    @Override
    public void onCreate() {
        super.onCreate();
        application = this;
        initARouter();
        String rootProject = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "yjh" + File.separator;
        String LogsFolders = rootProject + "ulogs" + File.separator;
        LogsUtils.init(this).setGlobalTag("AppLogs").setDir(LogsFolders).setSaveDays(7);

        ShareUtils.init(this);
        HttpHelper.init(new OkhttpUtil());
        ToastUtil.initialize(this);
        initCrash();
        initOther();
    }


    protected  void initOther(){

    }


    public void initCrash() {
        AppCrashHandler crashHandler = AppCrashHandler.getInstance();
        crashHandler.init(getApplicationContext());
        CrashReport.initCrashReport(this, "0bd2ab4be1", BuildConfig.DEBUG);
        CrashReport.setDeviceModel(this, Build.MODEL);
    }

    private void initARouter() {
        if (BuildConfig.DEBUG) {
            //debug下新增需要调用，才能跳转新增的路径
            ARouter.openLog();   // 打印日志
            ARouter.openDebug(); // 开启调试模式(如果在InstantRun模式下运行，必须开启调试模式！线上版本需要关闭,否则有安全风险)
        }
        ARouter.init(this); // 尽可能早，推荐在Application中初始化
    }

}
